%% @author Mochi Media <dev@mochimedia.com>
%% @copyright 2010 Mochi Media <dev@mochimedia.com>

%% @doc gameweb.

-module(gameweb).
-author("Mochi Media <dev@mochimedia.com>").
-export([
        start/2
        ,start_ssl/4
        ,stop/0
    ]
).

ensure_started(App) ->
    case application:start(App) of
        ok ->
            ok;
        {error, {already_started, App}} ->
            ok
    end.


%% @doc Start the gameweb http server.
-spec start(WebPort :: pos_integer(), HandleMod :: atom()) -> ok.
start(WebPort, HandleMod) ->
    %% gameweb_deps:ensure(),
    ensure_started(crypto),
    ok = application:start(gameweb),
    gameweb_sup:start_worker(WebPort, HandleMod).

%% @spec Start the gameweb https server.
start_ssl(WebPort, HandleMod, SslPrivateKeyPath, SslPublicKeyPath) ->
    ensure_started(crypto),
    ok = application:start(gameweb),
    gameweb_sup:start_ssl_worker(WebPort, HandleMod, SslPrivateKeyPath, SslPublicKeyPath).


%% @spec stop() -> ok
%% @doc Stop the gameweb server.
stop() ->
    application:stop(gameweb).
